package org.example.memora.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.memora.entity.NotifyMessage;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class NotificationService {

    private final SimpMessagingTemplate messagingTemplate;

    /**
     * 发送通知给某个用户（前端订阅路径为 /user/{userId}/topic/notifications）
     */
    public void sendToUser(Long userId, NotifyMessage message) {
        log.info("🚀 向用户 {} 发送通知: {}", userId, message);
        messagingTemplate.convertAndSend(
                "/topic/notifications-" + userId,
                message
        );
    }

//    public void sendToUser(Long userId, NotifyMessage message) {
//        log.info("🚀 向用户 {} 发送通知: {}", userId, message);
//        messagingTemplate.convertAndSendToUser(
//                String.valueOf(userId),
//                "/topic/notifications",
//                message
//        );
//    }
}
